Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect unused-asyncio-dangling-task (RUF006) on unused assignments #9060

Merged

Conversation

asafamr-mm
Copy link
Contributor

Summary

Fixes #8863 : Detect asyncio-dangling-task (RUF006) when discarding return value

Test Plan

added new two testcases, changed result of an old one that was made more specific

Copy link
Contributor

github-actions bot commented Dec 8, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

else {
continue;
};
asyncio_dangling_task(checker, value, diagnostics);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job figuring this out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try using typing::analyze::resolve_assignment here instead? It will also handle AnnAssign.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure how to do it without some refactoring.
I currently use assignment value expression which (if I'm not mistaken) is discarded after processing in resolve_assignment?

For now I've extended the pattern match to include AnnAssign as done in unnecessary_list_cast - but would gladly change it

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! A few small comments. Thank you so much for taking this on.

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@charliermarsh charliermarsh changed the title RUF006 unused asyncio dangling task should trigger Detect unused-asyncio-dangling-task (RUF006) on unused assignments Dec 9, 2023
@charliermarsh charliermarsh added the bug Something isn't working label Dec 9, 2023
@charliermarsh charliermarsh enabled auto-merge (squash) December 9, 2023 21:06
@charliermarsh charliermarsh merged commit 6c2613b into astral-sh:main Dec 9, 2023
16 checks passed
@hauntsaninja
Copy link
Contributor

I think this PR has caused ruff to start complaining even when assignments are to globals and nonlocals. Is that intentional?

@charliermarsh
Copy link
Member

@hauntsaninja - probably not — if you share an example I’m happy to ensure it’s fixed in the next release.

@hauntsaninja
Copy link
Contributor

Thanks, filed #9262 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect asyncio-dangling-task (RUF006) when discarding return value
4 participants